using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.Graphics.Drawables.Shapes;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Views.Animations;
using Android.Graphics.Drawables;
using Android.Graphics;

namespace GBU.Activities
{
    [Activity(Label = "My Activity")]
    public class CountDownActivity : Activity
    {
       // private Animation scaleAnimation;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Log.Debug("ANIM", "starting anim activity.");
            // Create your application here
            SetContentView(Resource.Layout.CountDown);

            try
            {
                Log.Debug("ANIM", "begin animation.");

                var scaleAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.countdown2);
                var alphaAnimation = AnimationUtils.LoadAnimation(this, Resource.Animation.countdown);

                AnimationSet animSet=new AnimationSet(true);

                animSet.AddAnimation(scaleAnimation);
                animSet.AddAnimation(alphaAnimation);

                Log.Debug("ANIM", "get target textview.");
                var target = FindViewById<TextView>(Resource.Id.textView1);

                int startDuri = 1;

                Log.Debug("ANIM", "show 1.");
                target.Text = "1";
                target.StartAnimation(animSet);

                startDuri += 1000;

              //  target.ClearAnimation();

                //SetContentView(new AniShape(this));

                Log.Debug("ANIM", "show 2.");
                //print 2
                new Handler().PostDelayed(() =>
                    {
                        target.Text = "2";
                        target.StartAnimation(animSet);

                        //target.ClearAnimation();
                    }, startDuri);
                startDuri += 1000;

                Log.Debug("ANIM", "show 3");
                //print 3
                new Handler().PostDelayed(() =>
                    {
                        target.Text = "3";
                        target.StartAnimation(animSet);
                        //target.ClearAnimation();
                    }, startDuri);
                startDuri += 1000;

                Log.Debug("ANIM", "show 3");
                //print 3
                new Handler().PostDelayed(() =>
                {
                    target.Text = "GO";
                    target.StartAnimation(animSet);
                    //target.ClearAnimation();
                }, startDuri);
                startDuri += 1000;


                Log.Debug("ANIM", "show 3");
                //print 3
                new Handler().PostDelayed(() =>
                    {
                        target.Text = "";
                        //target.ClearAnimation();
                        Intent i=new Intent(this,typeof(RunActivity));
                        StartActivity(i);
                        this.Finish();
                    }, startDuri);
            }
            catch (Exception e)
            {
                Log.Debug("ANIM","Anim Error: " + e.Message + "|" + e.StackTrace);
            }

        }


    }
}